using System;
using System.ComponentModel;
using RollManager.Library.Utils;

namespace RollManager.Library.ActionSteps
{
    [Serializable]
    public class RunCommandStep : ActionStep
    {
        public string m_cmd = StepConstants.NAME;
        public string m_args = StepConstants.NAME;

        [Description( "Name and path of the command to execute." )]
        public string Command
        {
            get
            {
                return m_cmd;
            }
            set
            {
                if( string.IsNullOrEmpty( value ) )
                {
                    throw new ArgumentException( "Command cannot be empty." );
                }
                else
                {
                    m_cmd = value.Trim();
                }
            }
        }

        [Description( "The command line arugments that accompany the command." )]
        public string Arguments
        {
            get
            {
                return m_args;
            }
            set
            {
                m_args = value.Trim();
            }
        }

        public override string Name
        {
            get { return "Run Command"; }
        }

        protected override void Run()
        {
            Common.RunCommand( m_cmd, m_args, Progress );
        }

        protected override void Simulate()
        {
            Progress.AddFormat( "Simulated running of command {0} with arguments {1}.", m_cmd, m_args );
        }
    }
}
